close all
%% Read Data
Files={'42.txt';'61.txt'};

for j=1:2
    File=Files{j};
    opts = detectImportOptions(File);
    i=20;
    opts.VariableNamesLine = i;
    opts.VariableUnitsLine=i+1;
    opts.DataLines=[i+2 Inf];
    Rheos{j}=readtable(File,opts);
end
%% Plot Torque - Time Relation

    T1=350;
    T2=550;
    fig=figure('Units','inches','Position',[1,1,3,2.5]);
    Rheo=Rheos{1};
    Rheo.Time=[1:length(Rheo.Meas_Pts_)]'/10;
    hold on
    y=Rheo.Torque(Rheo.Time>T1&Rheo.Time<=T2)*1000;
    plot(Rheo.Time(Rheo.Time>T1&Rheo.Time<=T2)-T1,y-1380,'DisplayName','With Suspension','linewidth',1)
    ylabel('\DeltaM - \muNm')
    ylabel('M - uNm')
    xlabel('t - s')

    Rheo=Rheos{2};
    y=Rheo.Torque(Rheo.Time>T1&Rheo.Time<=T2)*1000;
    plot(Rheo.Time(Rheo.Time>T1&Rheo.Time<=T2)-T1,y,'DisplayName','Without Suspension ','linewidth',1)

    ylim([690,1250])
    yticks([690,800,900,1020,1120,1220])
    yticklabels({'0','800','900','2400','2500','2600'})

    legend()
    set(gca,'fontsize',10)
    set(gca,'linewidth',1)  
    box on
    print(fig,['Two in One',' Torque-Time','.png'],'-r800','-dpng');        
    saveas(fig,['Two in One',' Torque-Time.eps'],'epsc')
    exportgraphics(gca,'Two in One.pdf') 
%%  Plot the PSD of Torque as a function of the frequency
T1=20;
T2=99999;
    Rheo=Rheos{1};
    [St1,Freq1]=FFT_of_signal(Rheo.Time(Rheo.Time>T1&Rheo.Time<=T2),Rheo.Torque(Rheo.Time>T1&Rheo.Time<=T2)*1000,false);
    Rheo=Rheos{2};
    [St2,Freq2]=FFT_of_signal(Rheo.Time(Rheo.Time>T1&Rheo.Time<=T2),Rheo.Torque(Rheo.Time>T1&Rheo.Time<=T2)*1000,false);
        
    fig=figure('Units','inches','Position',[1,1,2,1.75]);

        hold on
        plot(Freq1,smooth(St1),'linewidth',1,'DisplayName','Polymer Solution with Suspension')
        plot(Freq2,smooth(St2),'linewidth',1,'DisplayName','Polymer Solution')
        legend()
        xlabel('Frequency - Hz')
        ylabel('PSD - (uNm)^2')
        set(gca,'linewidth',1)
        set(gca,'fontsize',7)
        set(gca,'XScale','log')
        set(gca,'YScale','log')
        xlim([10^-2,5])
        ylim([10^-1,10^6])
        Velocity=4;
        plot(Velocity*[1,1]/2/pi,[1e-10,1e10],'k--','linewidth',1)
        set(gca, 'XColor','k', 'YColor','k')
        box on
        print(fig,['Two in One',' Torque-FFT','.png'],'-r800','-dpng');  
        saveas(fig,['Two in One',' Torque-FFT'],'epsc')
        exportgraphics(gca,['Two in One',' Torque-FFT.pdf']) 
